package cn.lijiajia3515.cairo.auth.framework.security.oauth2.server.authorization;

import cn.lijiajia3515.cairo.auth.framework.security.oauth2.server.authorization.client.CairoRegisteredClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.server.authorization.JwtEncodingContext;
import org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer;

@Slf4j
public class CairoOAuth2TokenCustomizer implements OAuth2TokenCustomizer<JwtEncodingContext> {

	@Override
	public void customize(JwtEncodingContext context) {
		log.debug("context: {}", context);
		context.getClaims().claim("grant_type", context.getAuthorizationGrantType().getValue()); // 授权方式
		context.getClaims().claim("client_id", context.getRegisteredClient().getClientId()); // client标识

		if (context.getRegisteredClient() instanceof CairoRegisteredClient) {
			context.getClaims().claim("app_id", ((CairoRegisteredClient) context.getRegisteredClient()).getApp()); // 应用标识
		}
	}
}
